package com.university.trade.util;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.UnsupportedEncodingException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.junit.Test;

public class Test1 {

	public static int a = 111;

	public static void main(String[] args) {
		/*
		 * String proTypeArr[] = new String[]{}; String s =
		 * "热门车型,特价车,海外定制,新车上市"; proTypeArr = s.split(",");
		 * System.out.println(proTypeArr[1]); System.out.println("+++" +
		 * "".split(",")[0]);
		 */
		// Runtime rn = Runtime.getRuntime();
		// String command = "notepad";
		// try {
		// rn.exec(command);
		// } catch (IOException e) {
		// e.printStackTrace();
		// }
		try {
			System.out.println(java.net.URLDecoder.decode("%E4%B8%AD%E5%9B%BD", "UTF-8"));
			System.out.println(java.net.URLEncoder.encode("分公司管理员", "UTF-8"));
			File file = new File("D:\\log.txt");
			if (!file.exists()) {
				file.createNewFile();
			}
			long time = file.lastModified();
			String fileName = String.valueOf(time);
			File newFile = new File("D:\\" + fileName + ".txt");
			if (!newFile.exists()) {
				newFile.createNewFile();
			}
			String s = "[{\"areaName\":\"\",\"foodName\":\"米饭\",\"unit\":\"碗\",\"addType\":\"FIX\"}]";
			s = s.substring(2, s.length() - 2);
			System.out.println(s);
			System.out.println(s.split(":").length);
			List<String> list = new ArrayList<String>();
			List<String> list1 = null;
			System.out.println(list.isEmpty());
			list = list1;
			System.out.println(list == null || list.size() == 0);
			SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
			System.out.println(sdf.parse("20151210161214"));
			// ;
			// FileOutputStream fos = new FileOutputStream(file);
			// byte[] b = "122".getBytes();
			// fos.write(b);
			// fos.close();
			// System.out.println(file.getName());
		} catch (UnsupportedEncodingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		System.out.println(a + 111);
		a = a + 111;
		System.out.println(a + 111);
	}
	/*
	 * public static void main(String[] args) { String str="<p>fda</p>";
	 * System.out.println(StringEscapeUtils.escapeHtml(str)); //存储结构 ： 河南理工大学 --
	 * 计算机学院 --- 软件工程 -- java1003---XXX Map<String,Object> forthLevelMap = new
	 * HashMap<String, Object>(); List<Map<String,Object>> forthLevelList = new
	 * ArrayList<Map<String,Object>>(); forthLevelMap.put("0327", "一鸣马");
	 * forthLevelMap.put("0328", "逗比帅"); forthLevelMap.put("0319", "土豪磊");
	 * forthLevelMap.put("0320", "傻逼王"); forthLevelList.add(forthLevelMap);
	 * Map<String,List<Map<String,Object>>> thirdLevelMap = new HashMap<String,
	 * List<Map<String,Object>>>();
	 * thirdLevelMap.put("JAVA1003",forthLevelList);
	 * List<Map<String,List<Map<String,Object>>>> thirdLevelList = new
	 * ArrayList<Map<String,List<Map<String,Object>>>>();
	 * thirdLevelList.add(thirdLevelMap);
	 * Map<String,List<Map<String,List<Map<String,Object>>>>> secondLevelMap =
	 * new HashMap<String, List<Map<String,List<Map<String,Object>>>>>();
	 * secondLevelMap.put("河南理工计算机科学与技术学院", thirdLevelList);
	 * List<Map<String,List<Map<String,List<Map<String,Object>>>>>>
	 * secondLevelList = new
	 * ArrayList<Map<String,List<Map<String,List<Map<String,Object>>>>>>();
	 * for(Map<String,List<Map<String,List<Map<String,Object>>>>> map :
	 * secondLevelList){ } }
	 */

	@Test
	public void testString() {
		Map<String,String> map = new HashMap<String,String>();
		String s1 = "t_001,t_002,t_003,t_004,t_005";//当前用户的标签集合
		for(int i = 0 ; i < 1000 ; i++){
			map.put("u" + i, s1);//模拟存放其他用户的标签
		}
		String s2 = "t_002,t_003,t_004,t_005";//模拟其他用户的标签集合
		for(int i = 1000 ; i < 10000 ; i++){
			map.put("u" + i, s2);//模拟存放其他用户的标签
		}
		String[] arr = s1.split(",");
		long startTime = new Date().getTime();
		System.out.println();
		Map<String,Integer> countMap = new HashMap<String,Integer>();
		Set<String> set = map.keySet();
		Iterator<String> it = set.iterator();
		int outNum = 0;// 用来控制输出前10条结果
		while(it.hasNext()){
			String key = it.next();
			String value = map.get(key);
			countMap.put(key, 0);
			for(int j = 0 ; j < arr.length;j++){
				if(value.indexOf(arr[j]) >= 0){
					countMap.put(key, countMap.get(key) + 1);
				}
			}
			outNum++;
			if(outNum <= 10){
				System.out.println("输出第" + outNum + "条匹配用户：" + key + ",匹配值为：" + countMap.get(key));
			}
		}
		long endTime = new Date().getTime();
		System.out.println("模拟10000个字符串,5个子串匹配,开始时间为：" +startTime+",结束时间为："+endTime+",耗时：" + (endTime - startTime) + "毫秒");
	}
}
